package com.yiyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiyi.common.annotation.Log;
import com.yiyi.common.core.controller.BaseController;
import com.yiyi.common.core.domain.AjaxResult;
import com.yiyi.common.enums.BusinessType;
import com.yiyi.system.domain.YyCommonFile;
import com.yiyi.system.service.IYyCommonFileService;
import com.yiyi.common.utils.poi.ExcelUtil;
import com.yiyi.common.core.page.TableDataInfo;

/**
 * 公共附件Controller
 * 
 * @author yiyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/system/file")
public class YyCommonFileController extends BaseController
{
    @Autowired
    private IYyCommonFileService yyCommonFileService;

    /**
     * 查询公共附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(YyCommonFile yyCommonFile)
    {
        startPage();
        List<YyCommonFile> list = yyCommonFileService.selectYyCommonFileList(yyCommonFile);
        return getDataTable(list);
    }

    /**
     * 导出公共附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "公共附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YyCommonFile yyCommonFile)
    {
        List<YyCommonFile> list = yyCommonFileService.selectYyCommonFileList(yyCommonFile);
        ExcelUtil<YyCommonFile> util = new ExcelUtil<YyCommonFile>(YyCommonFile.class);
        util.exportExcel(response, list, "公共附件数据");
    }

    /**
     * 获取公共附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yyCommonFileService.selectYyCommonFileById(id));
    }

    /**
     * 新增公共附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "公共附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YyCommonFile yyCommonFile)
    {
        return toAjax(yyCommonFileService.insertYyCommonFile(yyCommonFile));
    }

    /**
     * 修改公共附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "公共附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YyCommonFile yyCommonFile)
    {
        return toAjax(yyCommonFileService.updateYyCommonFile(yyCommonFile));
    }

    /**
     * 删除公共附件
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "公共附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yyCommonFileService.deleteYyCommonFileByIds(ids));
    }
}
